import { configureStore } from "@reduxjs/toolkit";
import counter from "./model/counter";
import storage from 'redux-persist/lib/storage';
import { persistReducer, persistStore } from 'redux-persist';

// 配置persist
const persistConfig = {
    key: 'root', // 存储的根键名
    version: 1, // 版本号，用于管理数据迁移
    storage, // 存储方式
};
  
const persistedReducer = persistReducer(persistConfig, counter);

const store=configureStore({
    reducer:{
        counter:persistedReducer,
    }
})

const persistor = persistStore(store); // 创建持久化实例

export type RootState = ReturnType<typeof store.getState>;
export type AppDispatch = typeof store.dispatch;

export { persistor }; // 导出持久化实例以便在应用中使用

export default store